package com.chb.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chihb
 * @create-time 2024/10/24 22:28
 * @description
 */
public class SubjectImpl implements Subject{
    private List<Observer> observers=new ArrayList<>();
    @Override
    public void addObserver(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void removeObserver(Observer observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyObserver(String meg) {
        for (Observer observer : observers) {
            observer.update(meg);
        }
    }
}
